﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Secure.Common;

namespace Secure.Tests.Core
{
    [TestFixture]
    public class SecuredResourceFixture
    {
        [Test]
        public void should_create_a_secured_resource()
        {
            ISecureUser user = new WindowsUser("someDomain", "david");

            Assert.AreEqual("someDomain\\david", user.UserName);

            SecuredResource securedResource = new ApplicationResource("MyAppName", "MyResourceName");
            securedResource.AddAllowedUser(user);

            Assert.AreEqual("application/MyAppName/MyResourceName", securedResource.GetResourcePath());

            bool isAllowed = securedResource.IsAllowedAccess(user);

            Assert.IsTrue(isAllowed);

            ISecureUser denied = new WindowsUser("foo", "bar");

            isAllowed = securedResource.IsAllowedAccess(denied);

            Assert.IsFalse(isAllowed);
        }

        [Test]
        public void should_create_a_security_manager()
        {
            ISecureUser user = new WindowsUser("someDomain", "david");

            SecuredResource securedResource = new ApplicationResource("MyAppName", "MyResourceName");
            securedResource.AddAllowedUser(user);

            ISecureGateway gateway = new GatewayService();
            gateway.AddSecuredResource(securedResource);

            bool isAllowed = gateway.IsAllowedAccess(user, "application/MyAppName/MyResourceName");

            Assert.IsTrue(isAllowed);
        }
    }
}